﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class Military : IEquatable<Military>
    {
        public void ImportList(List<Classes.Military> milList)
        {
            var mdb = new MedregDBDataContext();
            var ListMil = new List<Military>();
            foreach (var mil in milList)
            {
                Military mil1 = new Military() { ID = mil.ID, Name = mil.Name };
                Military query;

                if (mdb.Military.LongCount() == 0)
                {
                    mdb.Military.InsertOnSubmit(mil1);
                }
                else
                {
                    try
                    {
                        query = mdb.Military.Single(l => l.ID == mil1.ID);
                        query.Name = mil1.Name;
                       
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListMil.Contains(mil1))
                        {
                            mdb.Military.InsertOnSubmit(mil1);
                            ListMil.Add(mil1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(Military other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
